package model

// User 用户表
type Sworks struct {
	Id      int    `json:"id" form:"id"`
	Cno     int    `json:"cno" form:"cno"`
	Sno     string `json:"sno" form:"sno"`
	Sname   string `json:"sname" form:"sname"`
	Content string `json:"content" form:"content"`
	Cid     int    `json:"cid" form:"cid"`
	Path    string `json:"path" form:"path"`
	Teacher string `json:"teacher" form:"teacher"`
}

func SworksAll(cid string) ([]Sworks, error) {
	mods := make([]Sworks, 0, 4)
	err := DB.Select(&mods, "select * from swork where cid=?", cid)
	return mods, err
}

func Sworkadd(sno, sname, content, teacher, path string, cno, cid int) bool {

	result, _ := DB.Exec("INSERT INTO `swork` (`sno`, `sname`,`content`,`teacher`,`path`,`cno`,`cid` ) VALUES(?,?,?,?,?,?,?)", sno, sname, content, teacher, path, cno, cid)

	affect, _ := result.RowsAffected()
	if affect == 1 {
		return true
	}
	return false

}
